package com.zg.autoform.web;

import cn.hutool.core.bean.BeanUtil;
import com.zg.autoform.web.req.UpdateLayoutReq;
import com.zg.common.core.R;
import com.zg.common.core.dao.autoform.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Zxb
 */
@RestController
@RequiredArgsConstructor
@Api(tags = {"zxb视图字段功能"})
public class ZxbLayoutController {
    private final DiyLayoutDao layoutDao;

    @ApiOperation("查询视图字段基本信息")
    @GetMapping("/zxb/layout/info")
    public R findInfo(Long id) {
        DiyLayout layout = layoutDao.getById(id);
        return R.success(layout);
    }
    @PostMapping("/zxb/layout/update")
    public R update(@RequestBody UpdateLayoutReq req) {
        DiyLayout old = layoutDao.getById(req.getId());
        BeanUtil.copyProperties(req, old);
        layoutDao.updateById(old);
        return R.success();
    }
}
